$include("$theme/main.css");

$import("fp.controls.FeedViewContainer");
$import("fp.controls.SubscribePopup");
$import("fp.utils.DateTimeUtil");
$import("fp.utils.ContentExtractor");


with ($ns("fp"))
{
    fp.AppMainClass = function()
    {
        var me = this;
        
        me.feedViewContainer = null;
        me.subscribePopup = null;
        
        me.init = function()
        {            
            if (!g.Account.isAuthenticated)
            {
                chrome.tabs.getCurrent(function(p_tab){
                    chrome.tabs.remove(p_tab.id);
                });
                window.open("Login.html");
                return;
            }
            
            $translate(document.body);
            $(document.body).css("backgroundImage", "url(" + $mappath("~/wallpapers/Wallpaper-02.png") + ")");
            $("body > #main > #top").userSelectable(false);
            $("body > #main > #top > .toolbar > li").click(_toolbarItem_click);
            
            me.feedViewContainer = new fp.controls.FeedViewContainer($("#feedViewContainer"));
            me.feedViewContainer.init();
            
            me.subscribePopup = new fp.controls.SubscribePopup($("#subscribePopup"));
            me.subscribePopup.init();
            
            
            me.subscribePopup.load();
            me.load("user/-/state/com.google/reading-list");
        };
        
        
        
        
        me.load = function(p_path)
        {
            if (me.feedViewContainer.path != p_path)
            {
                me.feedViewContainer.path = p_path;
                me.feedViewContainer.reload();
            }
        }
        
        
        

        
        function _account_onauthenticated(e)
        {
            
        }
        
        function _toolbarItem_click(e)
        {
            var $li = $(this);
            if ($li.hasClass("selected"))
            {
                return;
            }
            
            var id = $li.attr("id");
            switch (id)
            {
                case "explore":
                case "list":
                    me.feedViewContainer.switchView(id, true);
                    break;
            }
        }
        
        return me;
    };
}